cmake_minimum_required(VERSION 3.12)
project(my_c_string)

# 查找 Python 解释器和开发组件
find_package(Python COMPONENTS Interpreter Development REQUIRED)

# 添加 Python 扩展模块
add_library(my_c_string SHARED
    my_c_string.c
)

# 设置输出名称和位置
set_target_properties(my_c_string PROPERTIES
    PREFIX ""
    OUTPUT_NAME "my_c_string"
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)

# 平台特定配置
if(WIN32)
    # Windows 下设置正确的扩展名和链接选项
    set_target_properties(my_c_string PROPERTIES
        SUFFIX ".pyd"
        WINDOWS_EXPORT_ALL_SYMBOLS TRUE
    )
    
    # Windows 下不链接到 Python 库文件，只使用头文件
    target_include_directories(my_c_string PRIVATE
        ${Python_INCLUDE_DIRS}
    )
    
    target_link_libraries(my_c_string PRIVATE
        ${Python_LIBRARIES}
    )
else()
    # Unix/Linux 下的配置
    set_target_properties(my_c_string PROPERTIES
        SUFFIX ".so"
    )
    
    target_include_directories(my_c_string PRIVATE
        ${Python_INCLUDE_DIRS}
    )
    
    target_link_libraries(my_c_string PRIVATE
        ${Python_LIBRARIES}
    )
endif()

# 设置 C 标准
set_property(TARGET my_c_string PROPERTY C_STANDARD 99) 
